<?php
/**
 * #Celebrate Shieh
 *             ,%%%%%%%%,
 *           ,%%/\%%%%/\%%
 *          ,%%%\c "" J/%%%
 * %.       %%%%/ o  o \%%%
 * `%%.     %%%%    _  |%%%
 *  `%%     `%%%%(__Y__)%%'
 *  //       ;%%%%`\-/%%%'
 * ((       /  `%%%%%%%'
 *  \\    .'          |
 *   \\  /       \  | |
 *    \\/         ) | |
 *     \         /_ | |__
 *     (___________))))))) 攻城湿
 *
 *        _       _
 * __   _(_)_   _(_) __ _ _ __
 * \ \ / / \ \ / / |/ _` |'_ \
 *  \ V /| |\ V /| | (_| | | | |
 *   \_/ |_| \_/ |_|\__,_|_| |_|
 */

namespace App\Models\System;


use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    protected $guarded = [];

    // Rest omitted for brevity

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [ 'name', 'email', 'phone', 'password', 'is_show', 'static' ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [ 'remember_token', ];

    /**
     * 一对一关联
     * 用户和用户信息关联
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function info()
    {
        return $this->hasOne('App\Models\System\Info', 'uid', 'id');
    }

    public function article()
    {
        return $this->hasOne('App\Models\Blog\Article', 'user_id', 'id');
    }

    public function invitation()
    {
        return $this->hasOne('App\Models\Common\Invitation', 'user_id', 'id');
    }

    public function pInvitation()
    {
        return $this->hasMany('App\Models\Common\Invitation', 'p_user_id', 'id');
    }

    public function calculation()
    {
        return $this->hasMany('App\Models\Expansion\Calculation', 'uid', 'id');
    }

    public function calendar()
    {
        return $this->hasMany('App\Models\Expansion\Calendar', 'userID', 'id');
    }

    public function chats()
    {
        return $this->hasMany('App\Models\Expansion\Chat', 'name', 'id');
    }

    public function chatsClient()
    {
        return $this->hasMany('App\Models\Expansion\Chat', 'client_name', 'id');
    }

    public function comment()
    {
        return $this->hasMany('App\Models\Blog\Comment', 'user_id', 'id');
    }

    public function commentClient()
    {
        return $this->hasMany('App\Models\Blog\Comment', 'client_name', 'id');
    }

    public function globe()
    {
        return $this->hasMany('App\Models\Expansion\Globe', 'uid', 'id');
    }

    public function link()
    {
        return $this->hasMany('App\Models\Blog\Link', 'user_id', 'id');
    }

    public function lists()
    {
        return $this->belongsToMany('App\Models\Blog\Lists', 'list_users', 'user_id', 'list_id');
    }

    public function notice()
    {
        return $this->belongsToMany('App\Models\Blog\Notice');
    }

    static function CreateModel( $data )
    {
        return self::create($data);
    }

    static function FirstModel( $where, $with = [], $select = [ '*' ] )
    {
        return self::with($with)->where($where)->select($select)->first();
    }

    static function ExistsModel( $where )
    {
        return self::where($where)->exists();
    }

}
